/**
 *====================================================
 * 文件名称: FinanceWorkbenchActionApiImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年11月12日			chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.action.v1;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Vector;

import org.hibernate.Session;

import com.yuexunit.finance.common.util.CollectionUtils;
import com.yuexunit.finance.context.FinanceBaseAction;
import com.yuexunit.finance.context.FinanceSessionContext;
import com.yuexunit.finance.member.entity.EnterpriseCodeEntity;
import com.yuexunit.finance.member.entity.EnterpriseEntity;
import com.yuexunit.finance.member.service.EnterpriseCodeService;
import com.yuexunit.finance.project.action.v1.dto.AbnormalCastor;
import com.yuexunit.finance.project.action.v1.dto.BulkstockCastor;
import com.yuexunit.finance.project.action.v1.dto.BulkstockManagementCastor;
import com.yuexunit.finance.project.action.v1.dto.BulkstockPledgeCastor;
import com.yuexunit.finance.project.action.v1.dto.FinanceApplicationCastor;
import com.yuexunit.finance.project.action.v1.dto.FinanceLoanCastor;
import com.yuexunit.finance.project.action.v1.model.output.BadassetsHandleLineInfo;
import com.yuexunit.finance.project.action.v1.model.output.ContainerInventory;
import com.yuexunit.finance.project.action.v1.model.output.DetainedApplicationLineInfo;
import com.yuexunit.finance.project.action.v1.model.output.FinanceLineInfo;
import com.yuexunit.finance.project.action.v1.model.output.InterestDelayLineInfo;
import com.yuexunit.finance.project.action.v1.model.output.PersonalWorkbench;
import com.yuexunit.finance.project.action.v1.model.output.PickupApplicationLineInfo;
import com.yuexunit.finance.project.action.v1.model.output.PickupDelayApplicationLineInfo;
import com.yuexunit.finance.project.entity.BadassetsHandleEntity;
import com.yuexunit.finance.project.entity.ContainerInventoryEntity;
import com.yuexunit.finance.project.entity.DetainedApplicationEntity;
import com.yuexunit.finance.project.entity.FinanceApplicationEntity;
import com.yuexunit.finance.project.entity.InterestDelayApplicationEntity;
import com.yuexunit.finance.project.entity.PickupApplicationEntity;
import com.yuexunit.finance.project.entity.PickupDelayApplicationEntity;
import com.yuexunit.finance.project.entity.lexicon.ApplicationSimpleStateEnum;
import com.yuexunit.finance.project.entity.lexicon.FinanceStateEnum;
import com.yuexunit.finance.project.entity.lexicon.PickupTypeEnum;
import com.yuexunit.finance.project.entity.lexicon.ProductTypeEnum;
import com.yuexunit.finance.project.entity.lexicon.WarePickupStateEnum;
import com.yuexunit.finance.project.entity.lexicon.WarningFactorEnum;
import com.yuexunit.finance.project.service.AbnormalService;
import com.yuexunit.finance.project.service.CommissionExtractApplicationService;
import com.yuexunit.finance.project.service.DetainedApplicationService;
import com.yuexunit.finance.project.service.PickupApplicationWarehouseService;
import com.yuexunit.inject.ComponentFactory;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.hibernate.SessionRepository;
import com.yuexunit.util.StringUtil;

/**
 * @ClassName: FinanceWorkbenchActionApiImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年11月12日 上午10:16:18
 */
@Implements(FinanceWorkbenchActionApi.class)
public class FinanceWorkbenchActionApiImpl extends FinanceBaseAction implements FinanceWorkbenchActionApi {

	private DetainedApplicationService detainedApplicationService = ComponentFactory.loadClass(DetainedApplicationService.class);

	private AbnormalService abnormalService = ComponentFactory.loadClass(AbnormalService.class);
	
	private CommissionExtractApplicationService commissionExtractApplicationService = ComponentFactory.loadClass(CommissionExtractApplicationService.class);
	
	private WarningCenterActionApi warningCenterActionApi = ComponentFactory.loadClass(WarningCenterActionApi.class);
	
	private EnterpriseCodeService enterpriseCodeService = ComponentFactory.loadClass(EnterpriseCodeService.class);
	
	private PickupApplicationWarehouseService pickupApplicationWarehouseService = ComponentFactory.loadClass(PickupApplicationWarehouseService.class);

	@Override
	public PersonalWorkbench personalWorkbench(Boolean flag) {
		flag = flag == null ? Boolean.FALSE : Boolean.TRUE; 
		if (flag) {
			PersonalWorkbench pw = new PersonalWorkbench();
			PageCriteria pc = new PageCriteria(1, 100000);
			// 融资初审-融资列表
			List<Long> audits = financeApplicationService.countWaitAuditFinanceApplication();
			pw.setAudits(audits);
			pw.setAudit(audits.size());
			if (audits.size() > 0) {
//				List<Date> financeList1 = financeApplicationService.inquireWarningTime(pw.getAudits().toArray(new Long[pw.getAudit()]), "applicationCreateDatetime");
//		        for (Date financeLineInfo : financeList1) {
//		        	int d = DateUtils.hoursBetween(financeLineInfo, DateUtils.now());
//		        	if (getWarningTime("applicationCreateDatetime") <= d && d <getAgingTime("applicationCreateDatetime")) {
//		        		pw.setAuditsWarnings(pw.getAuditsWarnings() + 1);
//		        	} else if (d > getAgingTime("applicationCreateDatetime")) {
//		        		pw.setAuditsAgings(pw.getAuditsAgings() + 1);
//		        	}
//				}
				pw.setAuditsWarnings(0);
				pw.setAuditsAgings(0);
			} else {
				pw.setAuditsWarnings(0);
				pw.setAuditsAgings(0);
			}
			
			// 融资正审-融资列表
			List<Long> audits1 = financeApplicationService.countWaitAuditFinanceApplication1();
			pw.setAudits1(audits1);
			pw.setAudit1(audits1.size());
			
			// 融资协议-融资列表
//			List<Long> contracts = financeApplicationService.countWaitContractFinanceApplication();
//			pw.setContracts(contracts);
//			pw.setContract(contracts.size());
//			if (contracts.size() > 0) {
//				PageList<FinanceLineInfo> financeList2 = financeApplicationActionApi.inquireFinanceList(pw.getContracts().toArray(new Long[pw.getContract()]), null, null, null, null, null, null, null, null, null, null, null, null, null, null, pc);
//		        for (FinanceLineInfo financeLineInfo : financeList2) {
//		        	int d = DateUtils.hoursBetween(financeLineInfo.getConstractCreateDatetime(), DateUtils.now());
//		        	if (getWarningTime("constractCreateDatetime") <= d && d <getAgingTime("constractCreateDatetime")) {
//		        		pw.setContractsWarnings(pw.getContractsWarnings() + 1);
//		        	} else if (d > getAgingTime("constractCreateDatetime")) {
//		        		pw.setContractsAgings(pw.getContractsAgings() + 1);
//		        	}
//				}
//			} else {
//				pw.setContractsWarnings(0);
//				pw.setContractsAgings(0);
//			}
			//跳过融资协议
			pw.setContract(0);
			pw.setContractsWarnings(0);
			pw.setContractsAgings(0);
			
			// 融资合同-融资列表
			List<Long> contracts1 = financeApplicationService.countWaitContractFinanceApplication1();
			pw.setContracts1(contracts1);
			pw.setContract1(contracts1.size());
			
			// 待增补合同-融资列表
			List<Long> supplementContracts = financeApplicationService.countWaitSupplementContractFinanceApplication();
			pw.setSupplementContracts(supplementContracts);
			pw.setSupplementContract(supplementContracts.size());
			
			//合同签署-融资列表
			List<Long> contracts2 = new ArrayList<>();
			Session session = SessionRepository.getCurrentSession();
//			String sql = "SELECT FINANCE_ID FROM fin_loan_notice c WHERE FINANCE_ID IN (SELECT FINANCE_ID FROM finance_files_info b,SIGN_FILE_INFO a WHERE b.FILES_UUID LIKE a.FILE_UUID AND a.FILE_SIGN_STATE = 6 AND a.FILES_SIGN = 1 GROUP BY FINANCE_ID) AND c.LEADER2_AUDIT_STATE = 1 AND c.LEADER2_AUDIT_SUBMIT_STATE = 1";
			String sql = "SELECT FINANCE_ID FROM fin_loan_notice c WHERE FINANCE_ID IN (SELECT FINANCE_ID FROM finance_files_info b,SIGN_FILE_INFO a WHERE FIND_IN_SET(a.FILE_UUID,b.FILES_UUID) AND a.FILE_SIGN_STATE = 6 AND a.FILES_SIGN = 1 GROUP BY FINANCE_ID) AND c.LEADER2_AUDIT_STATE = 1 AND c.LEADER2_AUDIT_SUBMIT_STATE = 1";
			List<Object> datas = session.createSQLQuery(sql).addScalar("FINANCE_ID").list();
			for (Object l : datas) {
				contracts2.add(((BigInteger) l).longValue());
			}
			SessionRepository.closeCurrentSession();
			pw.setContracts2(contracts2);
			pw.setContract2(contracts2.size());
			
			// 通知监管&通知收货-融资列表
			List<Long> recieves = financeApplicationService.countWaitRecieveFinanceApplication();
			pw.setRecieves(recieves);
			pw.setRecieve(recieves.size());
			if (recieves.size() > 0) {
//				List<Date> financeList3 = financeApplicationService.inquireWarningTime(pw.getRecieves().toArray(new Long[pw.getRecieve()]), "receiveCreateDatetime");
//		        for (Date financeLineInfo : financeList3) {
//		        	int d = DateUtils.hoursBetween(financeLineInfo, DateUtils.now());
//		        	if (getWarningTime("receiveCreateDatetime") <= d && d <getAgingTime("receiveCreateDatetime")) {
//		        		pw.setRecievesWarnings(pw.getRecievesWarnings() + 1);
//		        	} else if (d > getAgingTime("receiveCreateDatetime")) {
//		        		pw.setRecievesAgings(pw.getRecievesAgings() + 1);
//		        	}
//				}
				pw.setRecievesWarnings(0);
        		pw.setRecievesAgings(0);
			} else {
				pw.setRecievesWarnings(0);
        		pw.setRecievesAgings(0);
			}
			
			// 监管确认-理货任务
			List<Long> supervisions = tallyingService.countWaitSupervisionTallying();
			pw.setSupervisions(supervisions);
			pw.setSupervision(supervisions.size());
			if (supervisions.size() > 0) {
//				List<Date> financeList4 = financeApplicationService.inquireWarningTime(pw.getSupervisions().toArray(new Long[pw.getSupervision()]), "supervisionCreateDatetime");
//		        for (Date financeLineInfo : financeList4) {
//		        	int d = DateUtils.hoursBetween(financeLineInfo, DateUtils.now());
//		        	if (getWarningTime("supervisionCreateDatetime") <= d && d <getAgingTime("supervisionCreateDatetime")) {
//		        		pw.setSupervisionsWarnings(pw.getSupervisionsWarnings() + 1);
//		        	} else if (d > getAgingTime("supervisionCreateDatetime")) {
//		        		pw.setSupervisionsAgings(pw.getSupervisionsAgings() + 1);
//		        	}
//				}
				pw.setSupervisionsWarnings(0);
        		pw.setSupervisionsAgings(0);
			} else {
				pw.setSupervisionsWarnings(0);
        		pw.setSupervisionsAgings(0);
			}
			
			// 放款申请-融资列表
			List<Long> loads1 = financeApplicationService.countWaitLoadFinanceApplication();
			List<Long> loads = new ArrayList<>();
			for (Long l : loads1) {
				FinanceApplicationEntity fae = financeApplicationService.inquireFinanceApplicationEntity(l);
				if (fae != null && FinanceStateEnum.WAIT_LOAN == fae.getFinanceState()) {
					loads.add(l);
				}
			}
			pw.setLoads(loads);
			pw.setLoad(loads.size());
			if (loads.size() > 0) {
//				List<Date> financeList5 = financeApplicationService.inquireWarningTime(pw.getLoads().toArray(new Long[pw.getLoad()]), "loanApplicationCreateDatetime");
//		        for (Date financeLineInfo : financeList5) {
//		        	int d = DateUtils.hoursBetween(financeLineInfo, DateUtils.now());
//		        	if (getWarningTime("loanApplicationCreateDatetime") <= d && d <getAgingTime("loanApplicationCreateDatetime")) {
//		        		pw.setLoadsWarnings(pw.getLoadsWarnings() + 1);
//		        	} else if (d > getAgingTime("loanApplicationCreateDatetime")) {
//		        		pw.setLoadsAgings(pw.getLoadsAgings() + 1);
//		        	}
//				}
				pw.setLoadsWarnings(0);
        		pw.setLoadsAgings(0);
			} else {
				pw.setLoadsWarnings(0);
        		pw.setLoadsAgings(0);
			}
			
			// 放款审核-
			List<Long> loadAudits = loanNoticeService.countWaitAuditLoadFinanceApplication();
			pw.setLoadAudits(loadAudits);
			pw.setLoadAudit(loadAudits.size());
			if (loadAudits.size() > 0) {
//				PageList<LoanNoticeLineInfo> loanNoticeList = financeLoanActionApi.inquireLoanNoticePageList(null, null, null, null, null, null, null,null, Boolean.FALSE, pc);
//		        for (LoanNoticeLineInfo loanNoticeLineInfo : loanNoticeList) {
//		        	int d = DateUtils.hoursBetween(loanNoticeLineInfo.getLoanAuditCreateTime(), DateUtils.now());
//		        	if (getWarningTime("loanAuditCreateTime") <= d && d <getAgingTime("loanAuditCreateTime")) {
//		        		pw.setLoadAuditsWarnings(pw.getLoadAuditsWarnings() + 1);
//		        	} else if (d > getAgingTime("loanAuditCreateTime")) {
//		        		pw.setLoadAuditsAgings(pw.getLoadAuditsAgings() + 1);
//		        	}
//				}
				pw.setLoadAuditsWarnings(0);
        		pw.setLoadAuditsAgings(0);
			} else {
				pw.setLoadAuditsWarnings(0);
        		pw.setLoadAuditsAgings(0);
			}
			
			// 运输通知-融资列表
			Set<ProductTypeEnum> ptes = CollectionUtils.convertSet(ProductTypeEnum.values());
			ptes.remove(ProductTypeEnum.PROXY_SALE);
			ptes.remove(ProductTypeEnum.PURCHASING_STORAGE);
			ptes.remove(ProductTypeEnum.FREIGHT_FACTORING);
			List<Long> fd = financeApplicationService.inquireFinanceIdByProductType(ptes);
			List<Long> transports = financeApplicationService.countWaitTransportFinanceApplication(fd);
			pw.setTransports(transports);
			pw.setTransport(transports.size());
			if (transports.size() > 0) {
//				List<Date> financeList6 = financeApplicationService.inquireWarningTime(pw.getTransports().toArray(new Long[pw.getTransport()]), "transportNoticeCreateDatetime");
//		        for (Date financeLineInfo : financeList6) {
//		        	int d = DateUtils.hoursBetween(financeLineInfo, DateUtils.now());
//		        	if (getWarningTime("transportNoticeCreateDatetime") <= d && d <getAgingTime("transportNoticeCreateDatetime")) {
//		        		pw.setTransportsWarnings(pw.getTransportsWarnings() + 1);
//		        	} else if (d > getAgingTime("transportNoticeCreateDatetime")) {
//		        		pw.setTransportsAgings(pw.getTransportsAgings() + 1);
//		        	}
//				}
				pw.setTransportsWarnings(0);
        		pw.setTransportsAgings(0);
			} else {
				pw.setTransportsWarnings(0);
        		pw.setTransportsAgings(0);
			}
			
			// 提货审批-提货申请
			List<Long> pickups = pickupApplicationService.countWaitAuditPickupApplication(fd);
			pw.setPickups(pickups);
			pw.setPickup(pickups.size());
			if (pickups.size() > 0) {
//				List<Date> pickupList1 = pickupApplicationService.inquireWarning(pw.getPickups().toArray(new Long[pw.getPickup()]), "pickupApplicationCreateDateTime");
//		        for (Date pickupApplicationLineInfo : pickupList1) {
//		        	int d = DateUtils.hoursBetween(pickupApplicationLineInfo, DateUtils.now());
//		        	if (getWarningTime("pickupApplicationCreateDatetime") <= d && d <getAgingTime("pickupApplicationCreateDatetime")) {
//		        		pw.setPickupsWarnings(pw.getPickupsWarnings() + 1);
//		        	} else if (d > getAgingTime("pickupApplicationCreateDatetime")) {
//		        		pw.setPickupsAgings(pw.getPickupsAgings() + 1);
//		        	}
//				}
				pw.setPickupsWarnings(0);
        		pw.setPickupsAgings(0);
			} else {
				pw.setPickupsWarnings(0);
        		pw.setPickupsAgings(0);
			}
			
			// 收款确认-提货申请
			List<Long> receivableses = pickupApplicationService.countWaitReceivablesPickupApplication();
			pw.setReceivableses(receivableses);
			pw.setReceivables(receivableses.size());
			if (receivableses.size() > 0) {
//				List<Date> pickupList2 = pickupApplicationService.inquireWarning(pw.getReceivableses().toArray(new Long[pw.getReceivables()]), "receiveConfirmCreateDateTime");
//		        for (Date pickupApplicationLineInfo : pickupList2) {
//		        	int d = DateUtils.hoursBetween(pickupApplicationLineInfo, DateUtils.now());
//		        	if (getWarningTime("receiveConfirmCreateDatetime") <= d && d <getAgingTime("receiveConfirmCreateDatetime")) {
//		        		pw.setReceivablesesWarnings(pw.getReceivablesesWarnings() + 1);
//		        	} else if (d > getAgingTime("receiveConfirmCreateDatetime")) {
//		        		pw.setReceivablesesAgings(pw.getReceivablesesAgings() + 1);
//		        	}
//				}
				pw.setReceivablesesWarnings(0);
        		pw.setReceivablesesAgings(0);
			} else {
				pw.setReceivablesesWarnings(0);
        		pw.setReceivablesesAgings(0);
			}
	        
			// 通知放货-提货申请
			List<Long> deliveries = pickupApplicationService.countWaitDeliveryPickupApplication();
			pw.setDeliveries(deliveries);
			pw.setDelivery(deliveries.size());
			if (deliveries.size() > 0) {
//				List<Date> pickupList3 = pickupApplicationService.inquireWarning(pw.getDeliveries().toArray(new Long[pw.getDelivery()]), "deliveryNoticeCreateDateTime");
//		        for (Date pickupApplicationLineInfo : pickupList3) {
//		        	int d = DateUtils.hoursBetween(pickupApplicationLineInfo, DateUtils.now());
//		        	if (getWarningTime("deliveryNoticeCreateDatetime") <= d && d <getAgingTime("deliveryNoticeCreateDatetime")) {
//		        		pw.setDeliveriesWarnings(pw.getDeliveriesWarnings() + 1);
//		        	} else if (d > getAgingTime("deliveryNoticeCreateDatetime")) {
//		        		pw.setDeliveriesAgings(pw.getDeliveriesAgings() + 1);
//		        	}
//				}
				pw.setDeliveriesWarnings(0);
        		pw.setDeliveriesAgings(0);
			} else {
				pw.setDeliveriesWarnings(0);
        		pw.setDeliveriesAgings(0);
			}
			
			// 监管解除-配送任务
			List<Long> relieves = deliveryService.countRelieveDelivery();
			pw.setRelieves(relieves);
			pw.setRelieve(relieves.size());
			//解除监管
			if (relieves.size() > 0) {
//				PageList<ContainerInventory> inventoryList = financeBulkstockActionApi.inquireBulkstockInventoryPageList(null, null, pw.getRelieves().toArray(new Long[pw.getRelieve()]), null, null, null, null, null,null, null,null,null, pc);
//		        for (ContainerInventory containerInventory : inventoryList) {
//		        	int d = DateUtils.hoursBetween(containerInventory.getSupervisionRelieveCreateTime(), DateUtils.now());
//		        	if (getWarningTime("supervisionRelieveCreateDatetime") <= d && d <getAgingTime("supervisionRelieveCreateDatetime")) {
//		        		pw.setRelievesWarnings(pw.getRelievesWarnings() + 1);
//		        	} else if (d > getAgingTime("supervisionRelieveCreateDatetime")) {
//		        		pw.setRelievesAgings(pw.getRelievesAgings() + 1);
//		        	}
//				}
				pw.setRelievesWarnings(0);
        		pw.setRelievesAgings(0);
			} else {
				pw.setRelievesWarnings(0);
        		pw.setRelievesAgings(0);
			}
	        
			// 提前还款-提前还款申请
			List<Long> aheads = pickupApplicationService.countWaitAuditAheadApplication();
			pw.setAheads(aheads);
			pw.setAhead(aheads.size());
			// 延期还款-延期还款申请
			List<Long> pickupDelays = pickupDelayApplicationService.countWaitAuditDelayApplication();
			pw.setPickupDelays(pickupDelays);
			pw.setPickupDelay(pickupDelays.size());
			// 延期计息-延期计息申请
			List<Long> interestDelays = interestDelayApplicationService.countWaitAuditDelayApplication();
			pw.setInterestDelays(interestDelays);
			pw.setInterestDelay(interestDelays.size());
			// 赎货审批-赎货申请
			List<Long> redeems = pickupApplicationService.countWaitAuditRedeemApplication();
			pw.setRedeems(redeems);
			pw.setRedeem(redeems.size());
			// 扣货申请-扣货申请(异常处理)
			List<Long> detaineds = detainedApplicationService.countWaitDetainedApplication();
			pw.setDetaineds(detaineds);
			pw.setDetained(detaineds.size());
			// 不良处置-融资列表
			List<Long> badassetses = financeApplicationService.countWaitBadassetsFinanceApplication();
			pw.setBadassetses(badassetses);
			pw.setBadassets(badassetses.size());
			// 异常处理-异常列表
			List<Long> abnormals = abnormalService.countWaitHandleAbnormal();
			pw.setAbnormals(abnormals);
			pw.setAbnormal(abnormals.size());
			// 应收复核-流水列表
			List<Long> receiptConfirms = financeMoneyStatementService.countreceiptConfirm();
			pw.setReceiptConfirms(receiptConfirms);
			pw.setReceiptConfirm(receiptConfirms.size());
			//补货审核
			List<Long> replenishAudits = financeCreditService.countReplenishAudit();
			pw.setReplenishAudit(replenishAudits.size());
			pw.setReplenishAudits(replenishAudits);
			//补货确认
			List<Long> replenishConfirms = financeCreditService.countReplenishConfirm();
			pw.setReplenishConfirm(replenishConfirms.size());
			pw.setReplenishConfirms(replenishConfirms);
			//保证金追加审核
			List<Long> bailAdditionAudits = financeCreditService.countBailAdditionAudits();
			pw.setBailAdditionAudit(bailAdditionAudits.size());
			pw.setBailAdditionAudits(bailAdditionAudits);
			//保证金退还审核
			List<Long> bailReturnAudits = bailReturnService.countBailReturnAudits();
			pw.setBailReturnAudit(bailReturnAudits.size());
			pw.setBailReturnAudits(bailReturnAudits);
			//融资预警
			List<Long> schemeResults = warningSchemeResultService.countSchemeResults(WarningFactorEnum.BULKSTOCK);
			pw.setSchemeResult(schemeResults.size());
			pw.setSchemeResults(schemeResults);
			//合同逾期预警
			List<Long> riskWarnings = warningSchemeResultService.countSchemeResults(WarningFactorEnum.FINANCE_APPLICATION);
			pw.setRiskWarning(riskWarnings.size());
			pw.setRiskWarnings(riskWarnings);
//			//风险预警
//			List<Long> riskWarnings = abnormalRiskService.countRsiskWarnings();
//			pw.setRiskWarning(riskWarnings.size());
//			pw.setRiskWarnings(riskWarnings);
			//保险审核
			List<Long> insurances = insuranceService.countInsurances();
			pw.setInsurance(insurances.size());
			pw.setInsurances(insurances);
			//分销商审核
			List<Long> distributors = enterpriseService.conutDistributors();
			pw.setDistributor(distributors.size());
			pw.setDistributors(distributors);
			//用户审核
			List<Long> enterprises = enterpriseService.countEnterprises();
			pw.setEnterprise(enterprises.size());
			pw.setEnterprises(enterprises);
			//开卡审核
			List<Long> userCards = userCardInfoService.countUserCards();
			pw.setUserCard(userCards.size());
			pw.setUserCards(userCards);
			//佣金提取
			List<Long> commissionExtracts = commissionExtractApplicationService.countCommissionExtract();
			pw.setCommissionExtract(commissionExtracts.size());
			pw.setCommissionExtracts(commissionExtracts);
			//待收款
			List<Long> receipts = financeMoneyStatementService.countWaitReceipt(FinanceSessionContext.getAccountTenantId());
			pw.setWaitReceipt(receipts.size());
			pw.setWaitReceipts(receipts);
			//待放款
			List<Long> loans = financeMoneyStatementService.countWaitLoan(FinanceSessionContext.getAccountTenantId());
			pw.setWaitLoan(loans.size());
			pw.setWaitLoans(loans);
			
			List<WarePickupStateEnum> ps = new ArrayList<>();
			//销售提货待提交
			ps.add(WarePickupStateEnum.UNKNOWN);
			List<Long> warehousePickupUnsubmit = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupUnsubmit(warehousePickupUnsubmit.size());
			pw.setWarehousePickupUnsubmits(warehousePickupUnsubmit);
			
			//销售提货待初审
			ps.clear();
			ps.add(WarePickupStateEnum.FIRST_APPROVE);
			List<Long> warehousePickupFirstApprove = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupFirstApprove(warehousePickupFirstApprove.size());
			pw.setWarehousePickupFirstApproves(warehousePickupFirstApprove);
			
			//销售提货合同上传
			ps.clear();
			ps.add(WarePickupStateEnum.WAIT_CONTRACT_UPLOAD);
			ps.add(WarePickupStateEnum.WAIT_CONTRACT_SUBMIT);
			ps.add(WarePickupStateEnum.CONTRACT_CALLBACK);
			ps.add(WarePickupStateEnum.PLATFORM_SIGNED);
			List<Long> warehousePickupUpload = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupUpload(warehousePickupUpload.size());
			pw.setWarehousePickupUploads(warehousePickupUpload);
			
			//销售提货合同签署
			ps.clear();
			ps.add(WarePickupStateEnum.WAIT_PLATFORM_SIGN);
			List<Long> warehousePickupSign = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupSign(warehousePickupSign.size());
			pw.setWarehousePickupSigns(warehousePickupSign);
			
			//销售提货政审
			ps.clear();
			ps.add(WarePickupStateEnum.SECOND_APPROVE);
			List<Long> warehousePickupSecondApprove = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupSecondApprove(warehousePickupSecondApprove.size());
			pw.setWarehousePickupSecondApproves(warehousePickupSecondApprove);
			
			//销售提货处理
			ps.clear();
			ps.add(WarePickupStateEnum.WAIT_RELEASE);
			List<Long> warehousePickupRelease = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupRelease(warehousePickupRelease.size());
			pw.setWarehousePickupReleases(warehousePickupRelease);
			
 			return pw;
		} else {
			PersonalWorkbench pw = new PersonalWorkbench();
			// 融资审批-融资列表
			List<Long> audits = financeApplicationService.countWaitAuditFinanceApplication();
			pw.setAudits(audits);
			pw.setAudit(audits.size());
			// 融资正审-融资列表
			List<Long> audits1 = financeApplicationService.countWaitAuditFinanceApplication1();
			pw.setAudits1(audits1);
			pw.setAudit1(audits1.size());
			// 融资合同-融资列表
			List<Long> contracts1 = financeApplicationService.countWaitContractFinanceApplication1();
			pw.setContracts1(contracts1);
			pw.setContract1(contracts1.size());
			// 待增补合同-融资列表
			List<Long> supplementContracts = financeApplicationService.countWaitSupplementContractFinanceApplication();
			pw.setSupplementContracts(supplementContracts);
			pw.setSupplementContract(supplementContracts.size());
			//合同签署-融资列表
			List<Long> contracts2 = new ArrayList<>();
			Session session = SessionRepository.getCurrentSession();
			String sql = "SELECT FINANCE_ID FROM fin_loan_notice c WHERE FINANCE_ID IN (SELECT FINANCE_ID FROM finance_files_info b,SIGN_FILE_INFO a WHERE FIND_IN_SET(a.FILE_UUID,b.FILES_UUID) AND a.FILE_SIGN_STATE = 6 AND a.FILES_SIGN = 1 GROUP BY FINANCE_ID) AND c.LEADER2_AUDIT_STATE = 1 AND c.LEADER2_AUDIT_SUBMIT_STATE = 1";
			List<Object> datas = session.createSQLQuery(sql).addScalar("FINANCE_ID").list();
			for (Object l : datas) {
				contracts2.add(((BigInteger) l).longValue());
			}
			SessionRepository.closeCurrentSession();
			pw.setContracts2(contracts2);
			pw.setContract2(contracts2.size());
			// 合同签订-融资列表
			List<Long> contracts = financeApplicationService.countWaitContractFinanceApplication();
			pw.setContracts(contracts);
			pw.setContract(contracts.size());
			// 通知监管&通知收货-融资列表
			List<Long> recieves = financeApplicationService.countWaitRecieveFinanceApplication();
			pw.setRecieves(recieves);
			pw.setRecieve(recieves.size());
			// 监管确认-理货任务
			List<Long> supervisions = tallyingService.countWaitSupervisionTallying();
			pw.setSupervisions(supervisions);
			pw.setSupervision(supervisions.size());
			// 放款申请-融资列表
			List<Long> loads1 = financeApplicationService.countWaitLoadFinanceApplication();
			List<Long> loads = new ArrayList<>();
			for (Long l : loads1) {
				FinanceApplicationEntity fae = financeApplicationService.inquireFinanceApplicationEntity(l);
				if (fae != null && FinanceStateEnum.WAIT_LOAN == fae.getFinanceState()) {
					loads.add(l);
				}
			}
			pw.setLoads(loads);
			pw.setLoad(loads.size());
			// 放款审核-
			List<Long> loadAudits = loanNoticeService.countWaitAuditLoadFinanceApplication();
			pw.setLoadAudits(loadAudits);
			pw.setLoadAudit(loadAudits.size());
			// 运输通知-融资列表
			Set<ProductTypeEnum> ptes = CollectionUtils.convertSet(ProductTypeEnum.values());
			ptes.remove(ProductTypeEnum.PROXY_SALE);
			ptes.remove(ProductTypeEnum.PURCHASING_STORAGE);
			ptes.remove(ProductTypeEnum.FREIGHT_FACTORING);
			List<Long> fd = financeApplicationService.inquireFinanceIdByProductType(ptes);
			List<Long> transports = financeApplicationService.countWaitTransportFinanceApplication(fd);
			pw.setTransports(transports);
			pw.setTransport(transports.size());
			// 提货审批-提货申请
			List<Long> pickups = pickupApplicationService.countWaitAuditPickupApplication(fd);
			pw.setPickups(pickups);
			pw.setPickup(pickups.size());
			// 收款确认-提货申请
			List<Long> receivableses = pickupApplicationService.countWaitReceivablesPickupApplication();
			pw.setReceivableses(receivableses);
			pw.setReceivables(receivableses.size());
			// 通知放货-提货申请
			List<Long> deliveries = pickupApplicationService.countWaitDeliveryPickupApplication();
			pw.setDeliveries(deliveries);
			pw.setDelivery(deliveries.size());
			// 监管解除-配送任务
			List<Long> relieves = deliveryService.countRelieveDelivery();
			pw.setRelieves(relieves);
			pw.setRelieve(relieves.size());
			// 提前还款-提前还款申请
			List<Long> aheads = pickupApplicationService.countWaitAuditAheadApplication();
			pw.setAheads(aheads);
			pw.setAhead(aheads.size());
			// 延期还款-延期还款申请
			List<Long> pickupDelays = pickupDelayApplicationService.countWaitAuditDelayApplication();
			pw.setPickupDelays(pickupDelays);
			pw.setPickupDelay(pickupDelays.size());
			// 延期计息-延期计息申请
			List<Long> interestDelays = interestDelayApplicationService.countWaitAuditDelayApplication();
			pw.setInterestDelays(interestDelays);
			pw.setInterestDelay(interestDelays.size());
			// 赎货审批-赎货申请
			List<Long> redeems = pickupApplicationService.countWaitAuditRedeemApplication();
			pw.setRedeems(redeems);
			pw.setRedeem(redeems.size());
			// 扣货申请-扣货申请(异常处理)
			List<Long> detaineds = detainedApplicationService.countWaitDetainedApplication();
			pw.setDetaineds(detaineds);
			pw.setDetained(detaineds.size());
			// 不良处置-融资列表
			List<Long> badassetses = financeApplicationService.countWaitBadassetsFinanceApplication();
			pw.setBadassetses(badassetses);
			pw.setBadassets(badassetses.size());
			// 异常处理-异常列表
			List<Long> abnormals = abnormalService.countWaitHandleAbnormal();
			pw.setAbnormals(abnormals);
			pw.setAbnormal(abnormals.size());
			// 应收复核-流水列表
			List<Long> receiptConfirms = financeMoneyStatementService.countreceiptConfirm();
			pw.setReceiptConfirms(receiptConfirms);
			pw.setReceiptConfirm(receiptConfirms.size());
			//补货审核
			List<Long> replenishAudits = financeCreditService.countReplenishAudit();
			pw.setReplenishAudit(replenishAudits.size());
			pw.setReplenishAudits(replenishAudits);
			//补货确认
			List<Long> replenishConfirms = financeCreditService.countReplenishConfirm();
			pw.setReplenishConfirm(replenishConfirms.size());
			pw.setReplenishConfirms(replenishConfirms);
			//保证金追加审核
			List<Long> bailAdditionAudits = financeCreditService.countBailAdditionAudits();
			pw.setBailAdditionAudit(bailAdditionAudits.size());
			pw.setBailAdditionAudits(bailAdditionAudits);
			//保证金退还审核
			List<Long> bailReturnAudits = bailReturnService.countBailReturnAudits();
			pw.setBailReturnAudit(bailReturnAudits.size());
			pw.setBailReturnAudits(bailReturnAudits);
			//融资预警
			List<Long> schemeResults = warningSchemeResultService.countSchemeResults(WarningFactorEnum.BULKSTOCK);
			pw.setSchemeResult(schemeResults.size());
			pw.setSchemeResults(schemeResults);
			//风险预警
			List<Long> riskWarnings = warningSchemeResultService.countSchemeResults(WarningFactorEnum.FINANCE_APPLICATION);
			pw.setRiskWarning(riskWarnings.size());
			pw.setRiskWarnings(riskWarnings);
//			//风险预警
//			List<Long> riskWarnings = abnormalRiskService.countRsiskWarnings();
//			pw.setRiskWarning(riskWarnings.size());
//			pw.setRiskWarnings(riskWarnings);
			//保险审核
			List<Long> insurances = insuranceService.countInsurances();
			pw.setInsurance(insurances.size());
			pw.setInsurances(insurances);
			//分销商审核
			List<Long> distributors = enterpriseService.conutDistributors();
			pw.setDistributor(distributors.size());
			pw.setDistributors(distributors);
			//用户审核
			List<Long> enterprises = enterpriseService.countEnterprises();
			pw.setEnterprise(enterprises.size());
			pw.setEnterprises(enterprises);
			//开卡审核
			List<Long> userCards = userCardInfoService.countUserCards();
			pw.setUserCard(userCards.size());
			pw.setUserCards(userCards);
			//佣金提取
			List<Long> commissionExtracts = commissionExtractApplicationService.countCommissionExtract();
			pw.setCommissionExtract(commissionExtracts.size());
			pw.setCommissionExtracts(commissionExtracts);
			//待收款
			List<Long> receipts = financeMoneyStatementService.countWaitReceipt(FinanceSessionContext.getAccountTenantId());
			pw.setWaitReceipt(receipts.size());
			pw.setWaitReceipts(receipts);
			//待放款
			List<Long> loans = financeMoneyStatementService.countWaitLoan(FinanceSessionContext.getAccountTenantId());
			pw.setWaitLoan(loans.size());
			pw.setWaitLoans(loans);
			
			List<WarePickupStateEnum> ps = new ArrayList<>();
			//销售提货待提交
			ps.add(WarePickupStateEnum.UNKNOWN);
			List<Long> warehousePickupUnsubmit = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupUnsubmit(warehousePickupUnsubmit.size());
			pw.setWarehousePickupUnsubmits(warehousePickupUnsubmit);
			
			//销售提货待初审
			ps.clear();
			ps.add(WarePickupStateEnum.FIRST_APPROVE);
			List<Long> warehousePickupFirstApprove = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupFirstApprove(warehousePickupFirstApprove.size());
			pw.setWarehousePickupFirstApproves(warehousePickupFirstApprove);
			
			//销售提货合同上传
			ps.clear();
			ps.add(WarePickupStateEnum.WAIT_CONTRACT_UPLOAD);
			ps.add(WarePickupStateEnum.WAIT_CONTRACT_SUBMIT);
			ps.add(WarePickupStateEnum.CONTRACT_CALLBACK);
			ps.add(WarePickupStateEnum.PLATFORM_SIGNED);
			List<Long> warehousePickupUpload = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupUpload(warehousePickupUpload.size());
			pw.setWarehousePickupUploads(warehousePickupUpload);
			
			//销售提货合同签署
			ps.clear();
			ps.add(WarePickupStateEnum.WAIT_PLATFORM_SIGN);
			List<Long> warehousePickupSign = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupSign(warehousePickupSign.size());
			pw.setWarehousePickupSigns(warehousePickupSign);
			
			//销售提货政审
			ps.clear();
			ps.add(WarePickupStateEnum.SECOND_APPROVE);
			List<Long> warehousePickupSecondApprove = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupSecondApprove(warehousePickupSecondApprove.size());
			pw.setWarehousePickupSecondApproves(warehousePickupSecondApprove);
			
			//销售提货处理
			ps.clear();
			ps.add(WarePickupStateEnum.WAIT_RELEASE);
			List<Long> warehousePickupRelease = pickupApplicationWarehouseService.countPickupApplicationWarehouse(ps);
			pw.setWarehousePickupRelease(warehousePickupRelease.size());
			pw.setWarehousePickupReleases(warehousePickupRelease);
			
			return pw;
		}
	}

	@Override
	public PageList<PickupApplicationLineInfo> inquireWaitReceivablesPickupApplicationPageList(Long[] pickupIds, String enterpriseName, Integer productType, String financeNumber, String bulkstockName, PageCriteria page) {
		Long enterpriseId = null;
		if (FinanceSessionContext.isEnterprise()) {
			enterpriseId = FinanceSessionContext.getEnterpriseId();
		}
		List<Long> financeIds = financeApplicationService.getFinanceListIds3(productType,financeNumber);
		PageList<PickupApplicationEntity> pages = pickupApplicationService.inquirePickupApplicationPageLists(financeIds,pickupIds, enterpriseId, null, null, null, null, null, null, enterpriseName, bulkstockName, 1, null, page);
		PageList<PickupApplicationLineInfo> results = new PageList<>(page, pages.getTotalRecordCount());
		for (PickupApplicationEntity entity : pages) {
			results.add(BulkstockPledgeCastor.toPickupApplicationLineInfo(entity));
		}
		return results;
	}

	@Override
	public PageList<PickupApplicationLineInfo> inquireWaitDeliveryPickupApplicationPageList(Long[] pickupIds, String waybillNumber, String enterpriseName, Integer productType, String caseNumber,String financeNumber, String bulkstockName, PageCriteria page) {
//		Long enterpriseId = null;
//		if (FinanceSessionContext.isEnterprise()) {
//			enterpriseId = FinanceSessionContext.getEnterpriseId();
//		}
		if (StringUtil.isNotBlank(waybillNumber) || StringUtil.isNotBlank(caseNumber)) {
			List<Long> pickupId1s = containerInventoryService.inquirePickupIdFromContainerInventory(waybillNumber, caseNumber);
			if (pickupIds != null && pickupIds.length > 0) {
				Vector<Long> pis = new Vector<>();
				for (Long p : pickupId1s) {
					if (Arrays.asList(pickupIds).contains(p)){
						pis.add(p);
					}
				}
				pickupIds = pis.toArray(new Long[pis.size()]);
				if (pis.size() == 0) {
					pickupIds = new Long[]{-1L};
				}
			} else {
				pickupIds = pickupId1s.toArray(new Long[pickupId1s.size()]);
			}
		}
		List<Long> financeIds = financeApplicationService.getFinanceListIds3(productType,financeNumber);
		PageList<PickupApplicationEntity> pages = pickupApplicationService.inquirePickupApplicationPageLists(financeIds, pickupIds, null, null, null, null, null, null, null,enterpriseName,bulkstockName, null, null, page);
		PageList<PickupApplicationLineInfo> results = new PageList<>(page, pages.getTotalRecordCount());
		for (PickupApplicationEntity entity : pages) {
			results.add(BulkstockPledgeCastor.toPickupApplicationLineInfo(entity));
		}
		return results;
	}

	@Override
	public PageList<FinanceLineInfo> inquireEnterpriseInProcessFinanceApplicationPageList(Long enterpriseId, String waybillNumber, String caseNumber, String financeNumber, String financeContractNumber, String financeContractSerialNumber, 
			Integer productType, PageCriteria page) {
		// 扣除 状态为 取消/审批不通过/已完成/已评价/待提交/待确认
		Set<FinanceStateEnum> financeStates = CollectionUtils.convertSet(FinanceStateEnum.values());
		financeStates.remove(FinanceStateEnum.CANCEL);
		financeStates.remove(FinanceStateEnum.APPROVE_NOPASS);
		financeStates.remove(FinanceStateEnum.FINISH);
		financeStates.remove(FinanceStateEnum.UNSUMIT);
		financeStates.remove(FinanceStateEnum.EVALUATE);
		
		List<Long> financeIds = new ArrayList<>();
		if (StringUtil.isNotBlank(waybillNumber) || StringUtil.isNotBlank(caseNumber)) {
			financeIds = containerInventoryService.inquireFinanceIdFromContainerInventory(waybillNumber, caseNumber);
		}
		
		List<Long> financeContractIds = new ArrayList<>();
		if (StringUtil.isNotBlank(financeContractNumber) || StringUtil.isNotBlank(financeContractSerialNumber)) {
			financeContractIds = containerInventoryService.inquireFinanceIdFromContainerInventorys(financeContractNumber, financeContractSerialNumber);
		}
		
		if (enterpriseId == null) {
			enterpriseId = FinanceSessionContext.getEnterpriseId();
		}
		
		if (enterpriseId == null) {
			enterpriseId = 0L;
		}
		
		Long enterpriseId1= null;
		EnterpriseEntity enterprise = enterpriseService.inquireEnterprise(enterpriseId);
		if (StringUtil.isNotBlank(enterprise.getProxySaleCode())) {
			EnterpriseCodeEntity code = enterpriseCodeService.inquireEnterpriseCodeDetail(enterprise.getProxySaleCode(), null);
			enterpriseId1 = code.getEnterpriseId();
		}
		
//		PageList<FinanceApplicationEntity> financeEntities = financeApplicationService.inquireInProcessFinanceApplicationPageList(financeIds.toArray(new Long[financeIds.size()]), enterpriseId, enterpriseId1, financeStates, page);
		PageList<FinanceApplicationEntity> financeEntities = financeApplicationService.inquireInProcessFinanceApplicationPageLists(financeIds.toArray(new Long[financeIds.size()]),financeContractIds.toArray(new Long[financeContractIds.size()]),financeNumber, enterpriseId, enterpriseId1, financeStates, page);
		return FinanceApplicationCastor.toFinanceLineInfo(financeEntities, page);
	}
	
	@Override
	public PageList<FinanceLineInfo> inquireEnterpriseHistoryFinanceApplicationPageList(Long enterpriseId, PageCriteria page) {
		// 状态为 取消/审批不通过/已完成/已评价
		Set<FinanceStateEnum> financeStates = new HashSet<>();
		financeStates.add(FinanceStateEnum.CANCEL);
		financeStates.add(FinanceStateEnum.APPROVE_NOPASS);
		financeStates.add(FinanceStateEnum.FINISH);
		financeStates.add(FinanceStateEnum.EVALUATE);
		PageList<FinanceApplicationEntity> financeEntities = financeApplicationService.inquireInProcessFinanceApplicationPageList(null, enterpriseId, null, financeStates, page);
		return FinanceApplicationCastor.toFinanceLineInfo(financeEntities, page);
	}

	@Override
	public PageList<PickupDelayApplicationLineInfo> inquireEnterprisePickupDelayApplicationPageList(Long enterpriseId, PageCriteria page) {
		PageList<PickupDelayApplicationEntity> pages = pickupDelayApplicationService.inquirePickupDelayApplicationPageList(null, enterpriseId, null, null, ApplicationSimpleStateEnum.AGREE, null, null, page);
		PageList<PickupDelayApplicationLineInfo> results = new PageList<>(page, pages.getTotalRecordCount());
		for (PickupDelayApplicationEntity entity : pages) {
			results.add(BulkstockPledgeCastor.toPickupDelayApplicationLineInfo(entity));
		}
		return results;
	}

	@Override
	public PageList<InterestDelayLineInfo> inquireEnterpriseInterestDelayApplicationPageList(Long enterpriseId, PageCriteria page) {
		PageList<InterestDelayApplicationEntity> pageList = interestDelayApplicationService.inquireInterestDelayApplicationPageList(null, null, null, enterpriseId, null, ApplicationSimpleStateEnum.AGREE, page);
		PageList<InterestDelayLineInfo> resultList = new PageList<>(page, pageList.getTotalRecordCount());
		for (InterestDelayApplicationEntity entity : pageList) {
			resultList.add(FinanceLoanCastor.toInterestDelayLineInfo(entity));
		}
		return resultList;
	}

	@Override
	public PageList<ContainerInventory> inquireEnterpriseAbnormalContainerInventoryPageList(Long enterpriseId, PageCriteria page) {
		PageList<ContainerInventoryEntity> pages = containerInventoryService.inquireAbnormalContainerInventoryPageList(enterpriseId, page);
		PageList<ContainerInventory> results = new PageList<>(page, pages.getTotalRecordCount());
		for (ContainerInventoryEntity bie : pages) {
			results.add(BulkstockCastor.toContainerInventory(bie, Boolean.FALSE));
		}
		return results;
	}

	@Override
	public PageList<PickupApplicationLineInfo> inquireEnterpriseRansomPickupApplicationPageList(Long enterpriseId, PageCriteria page) {
		PageList<PickupApplicationEntity> pageList = pickupApplicationService.inquirePickupApplicationPageList(null, enterpriseId, null, null, ApplicationSimpleStateEnum.AGREE, PickupTypeEnum.REDEEM, null, null, page);
		PageList<PickupApplicationLineInfo> resultList = new PageList<>(page, pageList.getTotalRecordCount());
		for (PickupApplicationEntity entity : pageList) {
			resultList.add(BulkstockPledgeCastor.toPickupApplicationLineInfo(entity));
		}
		return resultList;
	}

	@Override
	public PageList<BadassetsHandleLineInfo> inquireEnterpriseBadassetsHandlePageList(Long enterpriseId, PageCriteria page) {
		PageList<BadassetsHandleEntity> pageList = badassetsHandleService.inquireBadassetsHandlePageList(null, null, null, enterpriseId, null, page);
		PageList<BadassetsHandleLineInfo> resultList = new PageList<>(page, pageList.getTotalRecordCount());
		for (BadassetsHandleEntity entity : pageList) {
			resultList.add(BulkstockManagementCastor.toBadassetsHandleLineInfo(entity));
		}
		return resultList;
	}

	@Override
	public PageList<DetainedApplicationLineInfo> inquireEnterpriseDetainedApplicationPageList(Long enterpriseId, PageCriteria page) {
		if (FinanceSessionContext.getEnterpriseId() != null) {
			enterpriseId = FinanceSessionContext.getEnterpriseId();
		}
		PageList<DetainedApplicationEntity> pageList = detainedApplicationService.inquireDetainedApplicationPageList(null, null, enterpriseId, ApplicationSimpleStateEnum.AGREE, page);
		PageList<DetainedApplicationLineInfo> results = new PageList<>(page, pageList.getTotalRecordCount());
		for (DetainedApplicationEntity entity : pageList) {
			results.add(AbnormalCastor.toDetainedApplicationLineInfo(entity));
		}
		return results;
	}

	private int getWarningTime(String auditWarningId){
		return warningCenterActionApi.inquireAuditWarning(auditWarningId).getWarningTime();
	}
	
	private int getAgingTime(String auditWarningId){
		return warningCenterActionApi.inquireAuditWarning(auditWarningId).getAgingTime();
	}
}
